﻿Imports System.IO

Public Class frmViewPersonInfo

    Public _isJudge As Boolean = False
    Public _isCourtClerk As Boolean = False
    Public _isLawyerPlaintiff As Boolean = False
    Public _isLawyerDefendant As Boolean = False
    Public _isLawyerThirdParty As Boolean = False
    Public _JudgeID As Long
    Public _CourtClerkID As Long
    Public _LawyerPlaintiffID As Long
    Public _LawyerDefendantID As Long
    Public _LawyerThirdPartyID As Long
    Public _CaseID As Long

    Dim dt As New DataTable
    Dim j As Integer = 0
    Dim tmp As Integer

    Private Sub frmViewJudge_CourtClerk_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        j = 0
        If _CaseID <> 0 Then
            If _isJudge Then
                getJudge()
            ElseIf _isCourtClerk Then
                getCourtClerk()
            ElseIf _isLawyerPlaintiff Then
                getLawyerPlaintiff()
            ElseIf _isLawyerDefendant Then
                getLawyerDefendant()
            ElseIf _isLawyerThirdParty Then
                getLawyerThirdParty()
            End If
        Else
            MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Protected Sub getJudge_byCaseID()
        Dim oJudge As New cJudge
        dt = oJudge.select_Judge_byCaseID(_CaseID)
    End Sub

    Protected Sub getCourtClerk_byCaseID()
        Dim oCourtClerk As New cCourtClerk
        dt = oCourtClerk.select_CourtClerk_byCaseID(_CaseID)
    End Sub

    Protected Sub getLawyerPlaintiff_byCaseID()
        Dim oLawyerPlaintiff As New cLawyerPlaintiff
        dt = oLawyerPlaintiff.select_LawyerPlaintiff_byCaseID(_CaseID)
    End Sub

    Protected Sub getLawyerDenfendant_byCaseID()
        Dim oLawyerDefendant As New cLawyerDefendant
        dt = oLawyerDefendant.select_LawyerDefendant_byCaseID(_CaseID)
    End Sub

    Protected Sub getLawyerThirdParty_byCaseID()
        Dim oLawyerThirdParty As New cLawyerThirdParty
        dt = oLawyerThirdParty.select_LawyerThirdParty_byCaseID(_CaseID)
    End Sub

    Protected Sub getJudge()
        Try
            getJudge_byCaseID()
            Dim i As Integer
            If dt.Rows.Count > 0 Then
                If _JudgeID <> 0 Then
                    For i = 0 To dt.Rows.Count - 1
                        If _JudgeID = dt.Rows(i)("JudgeID") Then
                            _JudgeID = dt.Rows(i)("JudgeID")
                            lblUserID.Text = dt.Rows(i)("UserID")
                            lblNo.Text = i + 1 & " of " & dt.Rows.Count

                            txtName.Text = dt.Rows(i)("JudgeName")
                            txtGender.Text = dt.Rows(i)("Gender")
                            dtpDOB.Value = dt.Rows(i)("DOB")
                            txtAddress.Text = dt.Rows(i)("Address")
                            txtTel.Text = dt.Rows(i)("Tel")
                            txtEmail.Text = dt.Rows(i)("Email")
                            'For Image
                            If dt.Rows(i)("Photo") IsNot DBNull.Value Then
                                Dim pic As Byte()
                                pic = dt.Rows(i)("Photo")
                                Dim streamPhoto As New MemoryStream(pic, True)
                                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                                Dim bmp1 As Bitmap = New Bitmap(bmp)
                                picPhoto.Image = bmp1
                                streamPhoto.Close()
                            Else
                                picPhoto.Image = My.Resources.Photo
                            End If
                            Exit For
                        End If
                        j += 1
                    Next
                Else
                    MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub getCourtClerk()
        Try
            getCourtClerk_byCaseID()
            Dim i As Integer
            If dt.Rows.Count > 0 Then
                If _CourtClerkID <> 0 Then
                    For i = 0 To dt.Rows.Count - 1
                        If _CourtClerkID = dt.Rows(i)("CourtClerkID") Then
                            _CourtClerkID = dt.Rows(i)("CourtClerkID")
                            lblUserID.Text = dt.Rows(i)("UserID")
                            lblNo.Text = i + 1 & " of " & dt.Rows.Count

                            txtName.Text = dt.Rows(i)("CourtClerkName")
                            txtGender.Text = dt.Rows(i)("Gender")
                            dtpDOB.Value = dt.Rows(i)("DOB")
                            txtAddress.Text = dt.Rows(i)("Address")
                            txtTel.Text = dt.Rows(i)("Tel")
                            txtEmail.Text = dt.Rows(i)("Email")
                            'For Image
                            If dt.Rows(i)("Photo") IsNot DBNull.Value Then
                                Dim pic As Byte()
                                pic = dt.Rows(i)("Photo")
                                Dim streamPhoto As New MemoryStream(pic, True)
                                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                                Dim bmp1 As Bitmap = New Bitmap(bmp)
                                picPhoto.Image = bmp1
                                streamPhoto.Close()
                            Else
                                picPhoto.Image = My.Resources.Photo
                            End If
                            Exit For
                        End If
                        j += 1
                    Next
                Else
                    MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub getLawyerPlaintiff()
        Try
            getLawyerPlaintiff_byCaseID()
            Dim i As Integer
            If dt.Rows.Count > 0 Then
                If _LawyerPlaintiffID <> 0 Then
                    For i = 0 To dt.Rows.Count - 1
                        If _LawyerPlaintiffID = dt.Rows(i)("LawyerPlaintiffID") Then
                            _LawyerPlaintiffID = dt.Rows(i)("LawyerPlaintiffID")
                            lblUserID.Text = dt.Rows(i)("UserID")
                            lblNo.Text = i + 1 & " of " & dt.Rows.Count

                            txtName.Text = dt.Rows(i)("LawyerName")
                            txtGender.Text = dt.Rows(i)("Gender")
                            dtpDOB.Value = dt.Rows(i)("DOB")
                            txtAddress.Text = dt.Rows(i)("Address")
                            txtTel.Text = dt.Rows(i)("Tel")
                            txtEmail.Text = dt.Rows(i)("Email")
                            'For Image
                            If dt.Rows(i)("Photo") IsNot DBNull.Value Then
                                Dim pic As Byte()
                                pic = dt.Rows(i)("Photo")
                                Dim streamPhoto As New MemoryStream(pic, True)
                                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                                Dim bmp1 As Bitmap = New Bitmap(bmp)
                                picPhoto.Image = bmp1
                                streamPhoto.Close()
                            Else
                                picPhoto.Image = My.Resources.Photo
                            End If
                            Exit For
                        End If
                        j += 1
                    Next
                Else
                    MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub getLawyerDefendant()
        Try
            getLawyerDenfendant_byCaseID()
            Dim i As Integer
            If dt.Rows.Count > 0 Then
                If _LawyerDefendantID <> 0 Then
                    For i = 0 To dt.Rows.Count - 1
                        If _LawyerDefendantID = dt.Rows(i)("LawyerDefendantID") Then
                            _LawyerDefendantID = dt.Rows(i)("LawyerDefendantID")
                            lblUserID.Text = dt.Rows(i)("UserID")
                            lblNo.Text = i + 1 & " of " & dt.Rows.Count

                            txtName.Text = dt.Rows(i)("LawyerName")
                            txtGender.Text = dt.Rows(i)("Gender")
                            dtpDOB.Value = dt.Rows(i)("DOB")
                            txtAddress.Text = dt.Rows(i)("Address")
                            txtTel.Text = dt.Rows(i)("Tel")
                            txtEmail.Text = dt.Rows(i)("Email")
                            'For Image
                            If dt.Rows(i)("Photo") IsNot DBNull.Value Then
                                Dim pic As Byte()
                                pic = dt.Rows(i)("Photo")
                                Dim streamPhoto As New MemoryStream(pic, True)
                                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                                Dim bmp1 As Bitmap = New Bitmap(bmp)
                                picPhoto.Image = bmp1
                                streamPhoto.Close()
                            Else
                                picPhoto.Image = My.Resources.Photo
                            End If
                            Exit For
                        End If
                        j += 1
                    Next
                Else
                    MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub getLawyerThirdParty()
        Try
            getLawyerThirdParty_byCaseID()
            Dim i As Integer
            If dt.Rows.Count > 0 Then
                If _LawyerThirdPartyID <> 0 Then
                    For i = 0 To dt.Rows.Count - 1
                        If _LawyerThirdPartyID = dt.Rows(i)("LawyerThirdPartyID") Then
                            _LawyerThirdPartyID = dt.Rows(i)("LawyerThirdPartyID")
                            lblUserID.Text = dt.Rows(i)("UserID")
                            lblNo.Text = i + 1 & " of " & dt.Rows.Count

                            txtName.Text = dt.Rows(i)("LawyerName")
                            txtGender.Text = dt.Rows(i)("Gender")
                            dtpDOB.Value = dt.Rows(i)("DOB")
                            txtAddress.Text = dt.Rows(i)("Address")
                            txtTel.Text = dt.Rows(i)("Tel")
                            txtEmail.Text = dt.Rows(i)("Email")
                            'For Image
                            If dt.Rows(i)("Photo") IsNot DBNull.Value Then
                                Dim pic As Byte()
                                pic = dt.Rows(i)("Photo")
                                Dim streamPhoto As New MemoryStream(pic, True)
                                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                                Dim bmp1 As Bitmap = New Bitmap(bmp)
                                picPhoto.Image = bmp1
                                streamPhoto.Close()
                            Else
                                picPhoto.Image = My.Resources.Photo
                            End If
                            Exit For
                        End If
                        j += 1
                    Next
                Else
                    MessageBox.Show("គ្មានពត៌មានបង្ហាញទេ", "បង្ហាញពត៌មាន", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub getJudge_Move()
        If j >= 0 And j < dt.Rows.Count Then
            _JudgeID = dt.Rows(j)("JudgeID")
            lblUserID.Text = dt.Rows(j)("UserID")
            lblNo.Text = j + 1 & " of " & dt.Rows.Count

            txtName.Text = dt.Rows(j)("JudgeName")
            txtGender.Text = dt.Rows(j)("Gender")
            dtpDOB.Value = dt.Rows(j)("DOB")
            txtAddress.Text = dt.Rows(j)("Address")
            txtTel.Text = dt.Rows(j)("Tel")
            txtEmail.Text = dt.Rows(j)("Email")
            'For Image
            If dt.Rows(j)("Photo") IsNot DBNull.Value Then
                Dim pic As Byte()
                pic = dt.Rows(j)("Photo")
                Dim streamPhoto As New MemoryStream(pic, True)
                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                Dim bmp1 As Bitmap = New Bitmap(bmp)
                picPhoto.Image = bmp1
                streamPhoto.Close()
            Else
                picPhoto.Image = My.Resources.Photo
            End If
        Else
            j = tmp
        End If
    End Sub

    Protected Sub getCourtClerk_Move()
        If j >= 0 And j < dt.Rows.Count Then
            _CourtClerkID = dt.Rows(j)("CourtClerkID")
            lblUserID.Text = dt.Rows(j)("UserID")
            lblNo.Text = j + 1 & " of " & dt.Rows.Count

            txtName.Text = dt.Rows(j)("CourtClerkName")
            txtGender.Text = dt.Rows(j)("Gender")
            dtpDOB.Value = dt.Rows(j)("DOB")
            txtAddress.Text = dt.Rows(j)("Address")
            txtTel.Text = dt.Rows(j)("Tel")
            txtEmail.Text = dt.Rows(j)("Email")
            'For Image
            If dt.Rows(j)("Photo") IsNot DBNull.Value Then
                Dim pic As Byte()
                pic = dt.Rows(j)("Photo")
                Dim streamPhoto As New MemoryStream(pic, True)
                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                Dim bmp1 As Bitmap = New Bitmap(bmp)
                picPhoto.Image = bmp1
                streamPhoto.Close()
            Else
                picPhoto.Image = My.Resources.Photo
            End If
        Else
            j = tmp
        End If
    End Sub

    Protected Sub getPlaintiff_Move()
        If j >= 0 And j < dt.Rows.Count Then
            _LawyerPlaintiffID = dt.Rows(j)("LawyerPlaintiffID")
            lblUserID.Text = dt.Rows(j)("UserID")
            lblNo.Text = j + 1 & " of " & dt.Rows.Count

            txtName.Text = dt.Rows(j)("LawyerName")
            txtGender.Text = dt.Rows(j)("Gender")
            dtpDOB.Value = dt.Rows(j)("DOB")
            txtAddress.Text = dt.Rows(j)("Address")
            txtTel.Text = dt.Rows(j)("Tel")
            txtEmail.Text = dt.Rows(j)("Email")
            'For Image
            If dt.Rows(j)("Photo") IsNot DBNull.Value Then
                Dim pic As Byte()
                pic = dt.Rows(j)("Photo")
                Dim streamPhoto As New MemoryStream(pic, True)
                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                Dim bmp1 As Bitmap = New Bitmap(bmp)
                picPhoto.Image = bmp1
                streamPhoto.Close()
            Else
                picPhoto.Image = My.Resources.Photo
            End If
        Else
            j = tmp
        End If
    End Sub

    Protected Sub getDefendant_Move()
        If j >= 0 And j < dt.Rows.Count Then
            _LawyerDefendantID = dt.Rows(j)("LawyerDefendantID")
            lblUserID.Text = dt.Rows(j)("UserID")
            lblNo.Text = j + 1 & " of " & dt.Rows.Count

            txtName.Text = dt.Rows(j)("LawyerName")
            txtGender.Text = dt.Rows(j)("Gender")
            dtpDOB.Value = dt.Rows(j)("DOB")
            txtAddress.Text = dt.Rows(j)("Address")
            txtTel.Text = dt.Rows(j)("Tel")
            txtEmail.Text = dt.Rows(j)("Email")
            'For Image
            If dt.Rows(j)("Photo") IsNot DBNull.Value Then
                Dim pic As Byte()
                pic = dt.Rows(j)("Photo")
                Dim streamPhoto As New MemoryStream(pic, True)
                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                Dim bmp1 As Bitmap = New Bitmap(bmp)
                picPhoto.Image = bmp1
                streamPhoto.Close()
            Else
                picPhoto.Image = My.Resources.Photo
            End If
        Else
            j = tmp
        End If
    End Sub

    Protected Sub getThirdPart_Move()
        If j >= 0 And j < dt.Rows.Count Then
            _LawyerThirdPartyID = dt.Rows(j)("LawyerThirdPartyID")
            lblUserID.Text = dt.Rows(j)("UserID")
            lblNo.Text = j + 1 & " of " & dt.Rows.Count

            txtName.Text = dt.Rows(j)("LawyerName")
            txtGender.Text = dt.Rows(j)("Gender")
            dtpDOB.Value = dt.Rows(j)("DOB")
            txtAddress.Text = dt.Rows(j)("Address")
            txtTel.Text = dt.Rows(j)("Tel")
            txtEmail.Text = dt.Rows(j)("Email")
            'For Image
            If dt.Rows(j)("Photo") IsNot DBNull.Value Then
                Dim pic As Byte()
                pic = dt.Rows(j)("Photo")
                Dim streamPhoto As New MemoryStream(pic, True)
                Dim bmp As Bitmap = New Bitmap(streamPhoto)
                Dim bmp1 As Bitmap = New Bitmap(bmp)
                picPhoto.Image = bmp1
                streamPhoto.Close()
            Else
                picPhoto.Image = My.Resources.Photo
            End If
        Else
            j = tmp
        End If
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        tmp = j
        j = 0
        If _isJudge Then
            getJudge_Move()
        ElseIf _isCourtClerk Then
            getCourtClerk_Move()
        ElseIf _isLawyerPlaintiff Then
            getPlaintiff_Move()
        ElseIf _isLawyerDefendant Then
            getDefendant_Move()
        ElseIf _isLawyerThirdParty Then
            getThirdPart_Move()
        End If
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        tmp = j
        j -= 1
        If _isJudge Then
            getJudge_Move()
        ElseIf _isCourtClerk Then
            getCourtClerk_Move()
        ElseIf _isLawyerPlaintiff Then
            getPlaintiff_Move()
        ElseIf _isLawyerDefendant Then
            getDefendant_Move()
        ElseIf _isLawyerThirdParty Then
            getThirdPart_Move()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        tmp = j
        j += 1
        If _isJudge Then
            getJudge_Move()
        ElseIf _isCourtClerk Then
            getCourtClerk_Move()
        ElseIf _isLawyerPlaintiff Then
            getPlaintiff_Move()
        ElseIf _isLawyerDefendant Then
            getDefendant_Move()
        ElseIf _isLawyerThirdParty Then
            getThirdPart_Move()
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        tmp = j
        j = dt.Rows.Count - 1
        If _isJudge Then
            getJudge_Move()
        ElseIf _isCourtClerk Then
            getCourtClerk_Move()
        ElseIf _isLawyerPlaintiff Then
            getPlaintiff_Move()
        ElseIf _isLawyerDefendant Then
            getDefendant_Move()
        ElseIf _isLawyerThirdParty Then
            getThirdPart_Move()
        End If
    End Sub
End Class